package com.net.core.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.RequestHandler;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.function.Predicate;

/**
 * Swagger2 UI配置
 * <pre>
 * 通过访问http://{yourip}:8090/api/swagger-ui.html查看发布的REST接口;
 * 账号登录的密码在 对应数据库的YXNET库的interface_user 表  密码由MD5加密，无法解密，只能重置。
 * </pre>
 */
@Configuration
@EnableSwagger2
//@EnableKnife4j
@Import(BeanValidatorPluginsConfiguration.class)
@ConditionalOnProperty(value = {"knife4j.enable"}, matchIfMissing = true)
public class SwaggerConfig {

    @Bean(value = "default")
    public Docket defaultApi1() {
        Predicate<RequestHandler> requestHandlerPredicate = RequestHandlerSelectors.basePackage("com.net.core");
        Docket docket = new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                //分组名称
                .groupName("1.0版本")
                //.globalOperationParameters(getGlobalOperationParameters())
                .select()
                //这里指定Controller扫描包路径
                .apis(requestHandlerPredicate)
                .paths(PathSelectors.any())
                .build();
        return docket;
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("管理端接口")
                .description("管理端接口       版权归成电医星所有")
                .termsOfServiceUrl("http://www.yxkj.com/")
                .contact(new Contact("成电医院星", "www.yxkj.com", ""))
                .version("1.0")
                .build();
    }

}
